<?php
header("Content-Type:json/html;charset=utf8;");

$config = require '../config.php';
require "../validToken.php";

$id = $_POST['id'];
$conn = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);

$info = isValidToken($conn);

if($info['status']){
    $sql = "delete from article where id = '$id'";
    $result = $conn->query($sql);
    if($result){
        $data = array();
        $result = ['code' =>1,  'msg' => "删除文章成功!"];
        require "../util/savelog.php";
        saveLog($conn, $info['user']['id'], "删除了一篇文章");
    }else{
        $result = ['code' =>0,  'msg' => "删除文章失败!"];
    }
}else{
    $result = ['code' =>-1,  'msg' => "token无效!"];
}
print_r(json_encode($result));
